#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QMessageBox>
#include<QDebug>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    //创建QMessageBox
    QMessageBox* messageBox = new QMessageBox(this);
    messageBox->setWindowTitle("对话框窗口标题");
    messageBox->setText("这是对话框得文本");
    messageBox->setIcon(QMessageBox::Warning);
    messageBox->setStandardButtons(QMessageBox::Ok|QMessageBox::Save|QMessageBox::Cancel);

//    QPushButton* button =new QPushButton("按钮",messageBox);
//    messageBox->addButton(button,QMessageBox::AcceptRole);

//connect 连接信号槽，针对当前点击得按钮进行相关得操作


    //弹出非模态对话框
//    messageBox->show();

    //弹出模态对话框。当对话框处于弹出状态的时候，代码就会在exec阻塞，一直到对话框被关闭
    int result = messageBox->exec();
    if(result == QMessageBox::Ok)
    {
        qDebug()<<"ok";
    }else if (result == QMessageBox::Save) {
        qDebug()<<"Save";
    }else if (result == QMessageBox::Cancel) {
        qDebug()<<"Cancel";
    }


   // delete messageBox;
    messageBox->setAttribute(Qt::WA_DeleteOnClose);
}
